package com.huarui.receivable.action;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.ewaf.framework.action.BaseAction;
import org.ewaf.framework.model.ListModel;

import com.huarui.receivable.service.ReceivableService;
import com.huarui.user.model.SessionMessage;
import com.huarui.user.security.UserHolder;
import com.huarui.util.JsonUtil;
import com.opensymphony.xwork2.Action;

public class ReceivableAction extends BaseAction {

	private static final long serialVersionUID = 1L;
	private Integer id;
	private Integer customerId;
	private String idsnot;
	private Integer start;
	private Integer limit;
	private String sort;
	private String dir;
	private Integer status;
	@SuppressWarnings("unchecked")
	private ListModel listModel=new ListModel();
	private SessionMessage sm;
	private ReceivableService receivableService;
	private Map<String,Object> resultMap=new HashMap<String,Object>();
	
	public String extList(){
		sm = UserHolder.getCurrentSessionMessage();
		listModel.setPage(start == null ? 0 : start / limit + 1);
		listModel.setPageSize(limit == null ? 10 : limit);
		listModel.setOrderBy(sort);
		if (dir != null)listModel.setDesc(dir.equals("DESC") ? true : false);
		Map<String,Object> map=new HashMap<String, Object>();
		map.put("companyId", sm.getCompanyId());
		if(idsnot!=null){
			Integer[] idsArray=JsonUtil.getIntegerArray4Json(idsnot);
			map.put("idsnot", idsArray);
		}
		if(customerId!=null){
			map.put("customerId", customerId);
		}
		if(status!=null){
			map.put("status", status);
		}
		receivableService.getListForPaging(listModel, map);
		resultMap.put("totalProperty", listModel.getTotal());
		resultMap.put("root", listModel.getResult());
		return Action.SUCCESS;
	}
	public String getReceivablesBycustomerId(){
		sm=UserHolder.getCurrentSessionMessage();
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("companyId", sm.getCompanyId());
		map.put("customerId", customerId);
		if(status!=null){
			map.put("status", status);
		}
		List<Map> list=receivableService.getListByConditions(map);
		resultMap.put("root", list);
		return Action.SUCCESS;
	}
	public Map<String, Object> getResultMap() {
		return resultMap;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public void setStart(Integer start) {
		this.start = start;
	}

	public void setLimit(Integer limit) {
		this.limit = limit;
	}

	public void setSort(String sort) {
		this.sort = sort;
	}

	public void setDir(String dir) {
		this.dir = dir;
	}

	public void setListModel(ListModel listModel) {
		this.listModel = listModel;
	}

	public void setSm(SessionMessage sm) {
		this.sm = sm;
	}

	public void setReceivableService(ReceivableService receivableService) {
		this.receivableService = receivableService;
	}
	public void setCustomerId(Integer customerId) {
		this.customerId = customerId;
	}
	public void setIdsnot(String idsnot) {
		this.idsnot = idsnot;
	}
	public void setStatus(Integer status) {
		this.status = status;
	}
	
}
